Skip to content

Conversation

@romainnorberg
Copy link

What:

  • Bug Fix
  • New Feature

Description:

Context: We want to retrieve conversations that were created via another service. In that service, when the API is called, the "input_file" values ​​are transmitted in base64.

When I try to list items for a conversation, I encounter an error:

In InputMessageContentInputFile.php line 42:
                                            
  [ErrorException]                          
  Warning: Undefined array key "file_data"  
                                            

Exception trace:
  at /var/www/project/vendor/openai-php/client/src/Responses/Responses/Input/InputMessageContentInputFile.php:42
 OpenAI\Responses\Responses\Input\InputMessageContentInputFile::from() at /var/www/project/vendor/openai-php/client/src/Responses/Conversations/Objects/Message.php:64
 OpenAI\Responses\Conversations\Objects\Message::{closure:OpenAI\Responses\Conversations\Objects\Message::from():62}() at n/a:n/a
 array_map() at /var/www/project/vendor/openai-php/client/src/Responses/Conversations/Objects/Message.php:61
 OpenAI\Responses\Conversations\Objects\Message::from() at /var/www/project/vendor/openai-php/client/src/Actions/Conversations/ItemObjects.php:60
 OpenAI\Actions\Conversations\ItemObjects::{closure:OpenAI\Actions\Conversations\ItemObjects::parse():59}() at n/a:n/a
 array_map() at /var/www/project/vendor/openai-php/client/src/Actions/Conversations/ItemObjects.php:58
 OpenAI\Actions\Conversations\ItemObjects::parse() at /var/www/project/vendor/openai-php/client/src/Responses/Conversations/ConversationItem.php:57
 OpenAI\Responses\Conversations\ConversationItem::from() at /var/www/project/vendor/openai-php/client/src/Responses/Conversations/ConversationItemList.php:51
 OpenAI\Responses\Conversations\ConversationItemList::{closure:OpenAI\Responses\Conversations\ConversationItemList::from():51}() at n/a:n/a
 array_map() at /var/www/project/vendor/openai-php/client/src/Responses/Conversations/ConversationItemList.php:50
 OpenAI\Responses\Conversations\ConversationItemList::from() at /var/www/project/vendor/openai-php/client/src/Resources/ConversationsItems.php:46
 OpenAI\Resources\ConversationsItems->list() at /var/www/project/src/project/CoreBundle/Command/TestPromptCommand.php:56
 project\CoreBundle\Command\TestPromptCommand->execute() at /var/www/project/vendor/symfony/console/Command/Command.php:318
 Symfony\Component\Console\Command\Command->run() at /var/www/project/vendor/symfony/console/Application.php:1110
 Symfony\Component\Console\Application->doRunCommand() at /var/www/project/vendor/symfony/framework-bundle/Console/Application.php:123
 Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/project/vendor/symfony/console/Application.php:359
 Symfony\Component\Console\Application->doRun() at /var/www/project/vendor/symfony/framework-bundle/Console/Application.php:77
 Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/project/vendor/symfony/console/Application.php:194
 Symfony\Component\Console\Application->run() at /var/www/project/vendor/symfony/runtime/Runner/Symfony/ConsoleApplicationRunner.php:49
 Symfony\Component\Runtime\Runner\Symfony\ConsoleApplicationRunner->run() at /var/www/project/vendor/autoload_runtime.php:29
 require_once() at /var/www/project/bin/console:11

Below is the raw API response (data has been masked), we can see that file_id is equal to null and that file_data is missing.

^ array:5 [
  "object" => "list"
  "data" => array:6 [
    0 => array:5 [
      "id" => "msg_0d1b41da7cb4903a0069..."
      "type" => "message"
      "status" => "completed"
      "content" => array:1 [
        0 => array:4 [
          "type" => "output_text"
          "annotations" => []
          "logprobs" => []
          "text" => """
            xxxxxxxxxxx
            """
        ]
      ]
      "role" => "assistant"
    ]
    1 => array:3 [
      "id" => "rs_0d1b41da7cb4903a00691debb7..."
      "type" => "reasoning"
      "summary" => []
    ]
    2 => array:5 [
      "id" => "msg_0d1b41da7cb4903a00691debb..."
      "type" => "message"
      "status" => "completed"
      "content" => array:1 [
        0 => array:2 [
          "type" => "input_text"
          "text" => "xxxxxxxxxxx"
        ]
      ]
      "role" => "user"
    ]
    3 => array:5 [
      "id" => "msg_0d1b41da7cb4903a00691de..."
      "type" => "message"
      "status" => "completed"
      "content" => array:1 [
        0 => array:4 [
          "type" => "output_text"
          "annotations" => []
          "logprobs" => []
          "text" => """
            xxxxxxxxxxx
		""" 
        ]
      ]
      "role" => "assistant"
    ]
    4 => array:3 [
      "id" => "rs_0d1b41da7cb4903a006..."
      "type" => "reasoning"
      "summary" => []
    ]
    5 => array:5 [
      "id" => "msg_0d1b41da7cb4903a00..."
      "type" => "message"
      "status" => "completed"
      "content" => array:3 [
        0 => array:3 [
          "type" => "input_file"
          "file_id" => null
          "filename" => "tuto_mapping.pdf"
        ]
        1 => array:3 [
          "type" => "input_file"
          "file_id" => null
          "filename" => "document.pdf"
        ]
        2 => array:2 [
          "type" => "input_text"
          "text" => "xxxxxxxxxxx"
        ]
      ]
      "role" => "user"
    ]
  ]
  "first_id" => "msg_0d1b41da7cb4903a0069..."
  "has_more" => false
  "last_id" => "msg_0d1b41da7cb4903a00691..."
]

@iBotPeaches
Copy link
Collaborator

By another service you mean not-OpenAI? The nulling of more fields will probably fail since tests expect those non-null, but I enabled build for you to see that.

@romainnorberg
Copy link
Author

By another service you mean not-OpenAI? The nulling of more fields will probably fail since tests expect those non-null, but I enabled build for you to see that.

It goes through the OpenAI API but via a python script. Here is an example:

python
response = client.responses.create(
        model=model,
        input=[
            {
                "role": "user",
                "content": [
                    {
                        "type": "input_file",
                        "filename": "tuto_mapping.pdf",
                        "file_data": f"data:application/pdf;base64,{tuto_mapping_base64_string}",
                    },
                    {
                        "type": "input_file",
                        "filename": "document.pdf",
                        "file_data": f"data:application/pdf;base64,{document_base64_string}",
                    },
                    {
                        "type": "input_text",
                        "text": "xxxxxx",
                    },
                ],
            },
        ],
        conversation=conversation_id # conv_691c21b669b48190af42f85a3...
    )

Thank you for enabling the tests, I will adapt them. @iBotPeaches

Copy link
Collaborator

@iBotPeaches iBotPeaches left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add 2 tests for the old form (string) and new (missing or null).

Sorry that a base test doesn't exist for ContentInputFile, but looking at this directory you should see its pretty simple to do

https://github.com/openai-php/client/tree/main/tests/Responses/Responses/Input

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants